package cn.iocoder.boot.controller.admin;

import cn.iocoder.boot.dto.ComponentPageDTO;
import cn.iocoder.boot.dto.ReplaceRelationManagementDTO;
import cn.iocoder.boot.entity.ReplaceRelationManagement;
import cn.iocoder.boot.service.ReplaceRelationService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "替代料管理")
@RestController
@RequestMapping("/replace")
public class ReplaceRelationController {

    @Resource
    private ReplaceRelationService replaceRelationManagementService;

    @PostMapping("/page")
    @Operation(summary = "分页查询")
    public CommonResult<Page<ReplaceRelationManagement>> getReplaceRelationManagementPage(@RequestBody ReplaceRelationManagementDTO dto) {
        return success(replaceRelationManagementService.getReplaceRelationManagementPage(dto));
    }


    @PostMapping
    @Operation(summary = "新增")
    public CommonResult<Boolean> createReplaceRelationManagement(@RequestBody ReplaceRelationManagementDTO dto) {
       return success(replaceRelationManagementService.createReplaceRelationManagement(dto));
    }

    @PutMapping
    public void updateReplaceRelationManagement(@RequestBody ReplaceRelationManagementDTO dto) {
        replaceRelationManagementService.updateReplaceRelationManagement(dto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public CommonResult<Boolean> deleteReplaceRelationManagement(@PathVariable Long id) {
       return success(replaceRelationManagementService.deleteReplaceRelationManagement(id));
    }

    @PostMapping("/getPageInfo")
    @Operation(summary = "获取国创元器件数据")
    public CommonResult<?> getPageInfo(@RequestBody ComponentPageDTO componentPageDTO) {
        return success(replaceRelationManagementService.getPageInfo(componentPageDTO));
    }
}
